package com.hxy.order.controller;

import com.hxy.basic.query.util.AjaxResult;
import com.hxy.basic.query.util.PageList;
import com.hxy.order.domain.AdoptOrder;
import com.hxy.order.query.AdoptOrderQuery;
import com.hxy.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){

        try{
            String payData = adoptOrderService.adoptOrderSubmit(params,request);
            // 将支付数据响应给前端，前端可以跳转到支付页面完成支付
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("下单失败！"+e.getMessage());
        }

    }

    /**
     * 获取管理员的领养订单
     * @param adoptOrderQuery
     * @param request
     * @return
     */
    @PostMapping("/admin")
    public PageList<AdoptOrder> adminAdoptOrder(@RequestBody AdoptOrderQuery adoptOrderQuery, HttpServletRequest request){
        return adoptOrderService.queryAdminOrder(adoptOrderQuery,request);
    }
    /**
     * 获取用户的领养订单
     * @param adoptOrderQuery
     * @param request
     * @return
     */
    @PostMapping("/user")
    public PageList<AdoptOrder> userAdoptOrder(@RequestBody AdoptOrderQuery adoptOrderQuery, HttpServletRequest request){
        return adoptOrderService.queryUserOrder(adoptOrderQuery,request);
    }
}




















